package com.zzyl.nursing.service.impl;

import cn.hutool.core.date.LocalDateTimeUtil;
import com.zzyl.common.userThreadLocal.UserThreadLocal;
import com.zzyl.nursing.mapper.ReservationMapper;
import com.zzyl.nursing.service.ReservationService;
import com.zzyl.nursing.vo.CountByTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class ReservationServiceImpl implements ReservationService {
    @Autowired
    private ReservationMapper reservationMapper;

    @Override
    public Integer selectCancelledCount() {
        //当天开始时间和结束时间
        long time = System.currentTimeMillis();
        LocalDateTime ldt = LocalDateTimeUtil.of(time);
        LocalDateTime startTime = ldt.toLocalDate().atStartOfDay();
        LocalDateTime endTime = startTime.plusDays(1);
        //获取当前线程用户id
        Long userId = UserThreadLocal.getUserId();
        Integer count = reservationMapper.selectCancelledCount(startTime, endTime, userId);
        return count;
    }

    @Override
    public List<CountByTime> selectCancelledCountByTime(Long time) {

        return reservationMapper.selectCancelledCountByTime(time);
    }
}
